#include "win_event_lock.h"
#include "elassert.h"

using namespace el;

WinEventLock::WinEventLock(bool manual_reset, bool init_status)
{
	event_lock_ = CreateEvent(
		NULL,               // default security attributes
		FALSE,              // manual-reset event
		FALSE,              // initial state is nonsignaled
		NULL				// object name
	);
	assert(event_lock_);
}



WinEventLock::~WinEventLock()
{
	if (event_lock_)
	{
		CloseHandle(event_lock_);
	}
}

unsigned long el::WinEventLock::wait(unsigned long timeout)
{
	return WaitForSingleObject(event_lock_, timeout);
}

bool el::WinEventLock::setEvent()
{
	return SetEvent(event_lock_) != 0;
}

bool el::WinEventLock::pulseEvent()
{
	return PulseEvent(event_lock_) != 0;
}

bool el::WinEventLock::resetEvent()
{
	return ResetEvent(event_lock_) != 0;
}
